package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.CustomerShadowInfoPinglun;
import com.aidex.biz.service.CustomerShadowInfoPinglunService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 客户跟进评论Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/biz/bizCustomerShadowInfoPinglun")
public class CustomerShadowInfoPinglunController extends BaseController
{
    @Autowired
    private CustomerShadowInfoPinglunService customerShadowInfoPinglunService;

    /**
     * 查询客户跟进评论列表
     */
    @GetMapping("/list")
    public R<PageInfo> list(CustomerShadowInfoPinglun customerShadowInfoPinglun, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                customerShadowInfoPinglun.setCompanyId(null);
        }else{
                     customerShadowInfoPinglun.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        customerShadowInfoPinglun.setPage(new PageDomain(request, response));
        return R.data(customerShadowInfoPinglunService.findPage(customerShadowInfoPinglun));
    }

    /**
     * 获取客户跟进评论详细信息
     */
    @GetMapping(value = "/{id}")
    public R<CustomerShadowInfoPinglun> detail(@PathVariable("id") String id)
    {
        return R.data(customerShadowInfoPinglunService.get(id));
    }

    /**
     * 新增客户跟进评论
     */
    @Log(title = "客户跟进评论", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  CustomerShadowInfoPinglun customerShadowInfoPinglun)
    {
        return R.status(customerShadowInfoPinglunService.save(customerShadowInfoPinglun));
    }

    /**
     * 修改客户跟进评论
     */
    @Log(title = "客户跟进评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated CustomerShadowInfoPinglun customerShadowInfoPinglun)
    {
        return R.status(customerShadowInfoPinglunService.save(customerShadowInfoPinglun));
    }


    /**
     * 删除客户跟进评论
     */
    @Log(title = "客户跟进评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(customerShadowInfoPinglunService.deleteCustomerShadowInfoPinglunByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(customerShadowInfoPinglunService.findMaxSort(new CustomerShadowInfoPinglun()));
    }

    /**
     * 导出客户跟进评论列表
     */
    @Log(title = "客户跟进评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(CustomerShadowInfoPinglun customerShadowInfoPinglun)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    customerShadowInfoPinglun.setCompanyId(null);
            }else{
                         customerShadowInfoPinglun.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<CustomerShadowInfoPinglun> list = customerShadowInfoPinglunService.findList(customerShadowInfoPinglun);
        ExcelUtil<CustomerShadowInfoPinglun> util = new ExcelUtil<CustomerShadowInfoPinglun>(CustomerShadowInfoPinglun.class);
        return util.exportExcel(list, "客户跟进评论数据");
    }

}
